package cn.contact.controller;

import cn.contact.pojo.Contact;
import cn.contact.service.ContactService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;


import java.util.List;

@Controller
public class ContactController {

    @Resource
    private ContactService cs;

    @RequestMapping("/ajaxsearch")
    @ResponseBody
    public List<Contact> getcontact(String cname) {

        return cs.getcontact(cname);

    }

    @RequestMapping("/add")
    @ResponseBody
    public int add(Contact c) {
        int count = cs.add(c);
        return count;
    }

    @RequestMapping("/toupdate")
    public String toupdate(Integer id, Model m) {
        Contact c = cs.getid(id);
        m.addAttribute("c", c);
        return "update.jsp";
    }

    @RequestMapping("/update")
    @ResponseBody
    public int update(Contact c) {
        int count = cs.update(c);
        return count;
    }
}
